// state:仓库存储数据的地方
import { reqCategoryList, reqGetbannerList, reqGetFloorList } from '@/api'

const state = {
  categoryList: [],
  getbannerList: [],
  getfloorList: []
}
// mutations:修改state的唯一手段
const mutations = {
  CATEGORYLIST (state, categoryList) {
    state.categoryList = categoryList
  },
  GETBANNERLIST (state, getbannerList) {
    state.getbannerList = getbannerList
  },
  GETFlOORLIST (state, getfloorList) {
    state.getfloorList = getfloorList
  },
}
// actions:处理action,可以书写自己的业务逻辑，也可以处理异步
const actions = {
  async categoryList ({ commit }) {
    let result = await reqCategoryList()
    if (result.code == 200) {
      commit('CATEGORYLIST', result.data)
    }
  },
  // 获取首页banner
  async getbannerList ({ commit }) {
    let result = await reqGetbannerList()
    if (result.code == 200) {
      commit('GETBANNERLIST', result.data)
    }
  },
  async getfloorList ({ commit }) {
    let result = await reqGetFloorList()
    if (result.code == 200) {
      commit('GETFlOORLIST', result.data)
    }
  }
}
// getters:理解为计算属性,用户简化仓库数据，让组件获取仓库的数据更加方便、
const getters = {}

export default {
  state, mutations, actions, getters
}
